package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.util.StrUtil;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.ChatgroupDao;
import io.renren.dto.ChatgroupDTO;
import io.renren.entity.ChatgroupEntity;
import io.renren.service.ChatgroupService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-05-28
 */
@Service
public class ChatgroupServiceImpl extends CrudServiceImpl<ChatgroupDao, ChatgroupEntity, ChatgroupDTO> implements ChatgroupService {

    @Override
    public QueryWrapper<ChatgroupEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<ChatgroupEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public ChatgroupEntity findOneByIMGroupID(String autoframenum) {
        QueryWrapper<ChatgroupEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("IMGroupID", autoframenum);
        List<ChatgroupEntity> list = baseDao.selectList(wrapper);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public void deleteByGroupId(String groupId) {
        QueryWrapper<ChatgroupEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("IMGroupID", groupId);
        baseDao.delete(wrapper);
    }
}